<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>倒计时</title>
  </head>
  <body>
    <h1></h1>
  </body>
  <script>
    setInterval(function () {
      //计算倒计时的思路 ： 目标日期-当前日期事件 = 时间差(转换成天时分秒)
      var date51 = new Date('2022-5-1').getTime(),
        thisDate = new Date().getTime()
      var times = date51 - thisDate
      var days = Math.floor(times / 1000 / 60 / 60 / 24),
        hours = Math.floor((times / 1000 / 60 / 60) % 24),
        se = Math.floor((times / 1000 / 60) % 60)
      m = Math.floor((times / 1000) % 60)
      document.getElementsByTagName('h1')[0].innerHTML =
        days + '天' + hours + '小时' + se + '分钟' + m + '秒'
    }, 1000)
  </script>
</html>
